package com.ugrow.Study_System.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import com.ugrow.Study_System.R;

public class MendAnimActivity extends AppCompatActivity {

    private ImageView animIv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mendanim);
        animIv = (ImageView) findViewById(R.id.act_mendanim_alpha_iv);
        animIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animation anim = AnimationUtils.loadAnimation(MendAnimActivity.this,R.anim.alpha);
                anim.setRepeatCount(Animation.INFINITE);
                anim.setRepeatMode(Animation.REVERSE);
                animIv.startAnimation(anim);
            }
        });
    }
    public void toRotate(View view){
        Animation anim = AnimationUtils.loadAnimation(MendAnimActivity.this,R.anim.rotate);

        animIv.startAnimation(anim);

    }

    public void toScale(View view) {
//        Animation anim = AnimationUtils.loadAnimation(MendAnimActivity.this, R.anim.scale);
//        animIv.startAnimation(anim);
        ScaleAnimation sa = new ScaleAnimation(1,0.5f,1,0.5f);
        sa.setDuration(2000);
        animIv.startAnimation(sa);
    }

    public void toTranslate(View view) {
        int width = getWindowManager().getDefaultDisplay().getWidth();
//        Animation anim = AnimationUtils.loadAnimation(MendAnimActivity.this, R.anim.translate);
        TranslateAnimation ta = new TranslateAnimation(0, width, 0, 0);
        ta.setDuration(300);
//        ta.setFillAfter(true);
//        ta.setFillBefore(true);
        ta.setFillEnabled(true);
        ta.setRepeatCount(3);
//        anim.setDuration(1500);
//        anim.setFillAfter(true);
        animIv.startAnimation(ta);

    }
}
